// ************************************************************
// Copyright © 2022
// File Name: server.go
// Author:
// Email:
// Created: 2022-03-14 22:07:07 (CST)
// Last Update:
//          By:
// Description:
// ************************************************************
package server

import (
	"light-pi/api"

	"github.com/gotomicro/ego"
	"github.com/gotomicro/ego/core/elog"
	"github.com/gotomicro/ego/server/egin"
)

func Engin() *egin.Component {
	server := egin.Load("server.http").Build()
	server.Static("/static", "static/")
	server.LoadHTMLGlob("web/views/*")
	server.GET("/", api.Index)
	server.POST("/light", api.Light)
	return server
}

func Web() {
	if err := ego.New().Serve(Engin()).Run(); err != nil {
		elog.Panic("startup", elog.FieldErr(err))
	}
}
